﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hyt.Core.Security;

namespace Hyt.Core
{
    /// <summary>
    /// 工作单元(ioc容器，aop容器，事务容器，鉴权容器)
    /// </summary>
    public interface IUnitOfWork
    {
        /// <summary>
        /// 添加工作部(用于事务)
        /// </summary>
        /// <param name="part"></param>
        void AddPart(IPartOfWork part);

        /// <summary>
        /// 提交工作
        /// </summary>
        void Commit();

        /// <summary>
        /// 获取实例(用于IOC,AOP)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        T Get<T>() where T : class;

        Object Get(Type type);

        /// <summary>
        /// 注入属性(用于IOC)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        void Inject<T>(T model) where T : class;

        /// <summary>
        /// 获取当前用户(用于鉴权)
        /// </summary>
        /// <returns></returns>
        IPrincipal GetCurrentPrincipal();

        /// <summary>
        /// 设置当前用户(用于鉴权)
        /// </summary>
        /// <param name="principal"></param>
        void SetPrincipal(IPrincipal principal);

        /// <summary>
        /// 获取会话ID(用于持续性的访问控制，如读写分离)
        /// </summary>
        /// <returns></returns>
        String GetSessionId();

        /// <summary>
        /// 设置会话ID(用于持续性的访问控制，如读写分离)
        /// </summary>
        /// <param name="sessionid"></param>
        void SetSessionId(string sessionid);
    }
}
